package com.haiertvbic.timeline.adapter;

import java.util.LinkedList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.haiertvbic.timeline.bean.ImageInfo;
import com.haiertvbic.tvnow.R;

public class TimeLineAdapter extends BaseAdapter {
	private Context mContext;
	private LayoutInflater mInflater;
	private LinkedList<ImageInfo> mImageInfos;

	public TimeLineAdapter(Context context, LinkedList<ImageInfo> imageInfos) {
		super();
		this.mContext = context;
		this.mImageInfos = imageInfos;
		this.mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mImageInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TimeLineViewHolder timeLineViewHolder = null;
		if (convertView != null && convertView.getTag() != null) {
			timeLineViewHolder = (TimeLineViewHolder) convertView.getTag();
		} else {
			timeLineViewHolder = new TimeLineViewHolder();
			convertView = (View) mInflater.inflate(R.layout.item, null);
			timeLineViewHolder.imageView = (ImageView) convertView
					.findViewById(R.id.time_line_img);
			timeLineViewHolder.textView = (TextView) convertView
					.findViewById(R.id.text_view);
			convertView.setTag(timeLineViewHolder);
		}
		if (mImageInfos != null && mImageInfos.size() > position) {
			if (mImageInfos.get(position) != null
					&& mImageInfos.get(position).getImageBitmap() != null) {
				timeLineViewHolder.imageView.setImageBitmap(mImageInfos.get(
						position).getImageBitmap());
//				timeLineViewHolder.imageView
//						.setBackgroundDrawable(new BitmapDrawable(mImageInfos
//								.get(position).getImageBitmap()));
				// timeLineViewHolder.textView.setText(position + "");
			}
		}
		return convertView;
	}

	private class TimeLineViewHolder {
		private ImageView imageView;
		private TextView textView;
	}
}
